<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link rel="stylesheet" href="./../assets/css/combined.css">
	<link rel="shortcut icon" href="./../favicon.ico" />
	<script src="http://www.google.com/jsapi" type="text/javascript"></script>
	<script type="text/javascript">
		var path = './../';
		var class_prefix = "Redis_Db::";
	</script>
	<script src="./../assets/js/combined.js"></script>
	<title>Redis_Db - Classes - FuelPHP Documentation</title>
</head>
<body>
	<div id="container">
		<header id="header">
			<div class="table">
				<h1>
					<strong>FuelPHP, a PHP 5.3 Framework</strong>
					Documentation
				</h1>

				<form id="google_search">
					<p>
						<span id="search_clear">&nbsp;</span>
						<input type="submit" name="search_submit" id="search_submit" value="search" />
						<input type="text" value="" id="search_input" name="search_input" />
					</p>
				</form>
			</div>
			<nav>

				<div class="clear"></div>
			</nav>
			<a href="#" id="toc_handle">table of contents</a>
			<div class="clear"></div>
		</header>

		<div id="cse">
			<div id="cse_point"></div>
			<div id="cse_content"></div>
		</div>

		<div id="main">

			<h2>Redis_Db Class</h2>

			<p>The Redis_Db class allows you to interact with a <a href="http://redis.io/">Redis</a> key-value store.</p>

			<h3 id="configuration">Configuration</h3>

			<p>For every Redis database connection there must be a config in redis array in app/config/&lt;environment&gt;/db.php. Configuration options and explanation are listed below. Every config requires to contain a hostname and a port.</p>

			<table class="config">
				<tbody>
					<tr class="header">
						<th>Param</th>
						<th>Type</th>
						<th>Default</th>
						<th>Description</th>

					</tr>
					<tr>
						<th>hostname</th>
						<td>string</td>
						<td><pre class="php"><code>'127.0.0.1'</code></pre></td>
						<td>
							Hostname
						</td>
					</tr>
					<tr>
						<th>port</th>
						<td>integer</td>
						<td><pre class="php"><code>6379</code></pre></td>
						<td>
							Port to use in the connection
						</td>
					</tr>
					<tr>
						<th>timeout</th>
						<td>mixed</td>
						<td><pre class="php"><code>null</code></pre></td>
						<td>
							Connection timeout
						</td>
					</tr>
					<tr>
						<th>database</th>
						<td>integer</td>
						<td><pre class="php"><code>0</code></pre></td>
						<td>
							Database zero-based index
						</td>
					</tr>
				</tbody>
			</table>

			<article>
				<h4 class="method" id="method_forge">forge($name = 'default', $config = array())</h4>
				<p>Create a new named redis instance, optionally with a custom configuration</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$name</kbd></th>
									<td><i><pre class="php"><code>'default'</code></pre></i></td>
									<td>The name of the new redis instance, as defined the application config db.php file.</td>
								</tr>
								<tr>
									<th><kbd>$config</kbd></th>
									<td><i><pre class="php"><code>array()</code></pre></i></td>
									<td>custom configuration, which will override the values defined in the db.php file.</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Fuel\Core\Redis Object</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// create the Redis 'mystore' instance
$redis = Redis_Db::forge('mystore');</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 class="method" id="method_instance">instance($name = 'default')</h4>
				<p>Return a named instance that was created earlier.</p>
				<table class="method">
					<tbody>
					<tr>
						<th class="legend">Static</th>
						<td>Yes</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$name</kbd></th>
									<td><i><pre class="php"><code>'default'</code></pre></i></td>
									<td>The name of the redis instance requested, as created using forge().</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Fuel\Core\Redis Object</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// retrieve the Redis 'mystore' instance
$redis = Redis_Db::instance('mystore');</code></pre>
						</td>
					</tr>
					</tbody>
				</table>
			</article>

			<article>
				<h4 id="redis_commands">Redis commands</h4>
				<p>Once you have created a redis object using the instance() method, every valid redis command (see the <a href="http://redis.io/commands">Redis Documentation</a>) as a method of that object.</p>
				<p>Some examples:</p>
				<pre class="php"><code>// create the Redis 'mystore' instance
$redis = Redis_Db::forge('mystore');

// create some test data
$redis->rpush('particles', 'proton');
$redis->rpush('particles', 'electron');
$redis->rpush('particles', 'neutron');

// fetch the range
$particles = $redis->lrange('particles', 0, -1);

// count the number of elements
$particle_count = $redis->llen('particles');

// display the results
echo "&lt;p>The {$particle_count} particles that make up atoms are:&lt;/p>";
echo "&lt;ul>";
foreach ($particles as $particle) {
  echo "&lt;li>{$particle}&lt;/li>";
}
echo "&lt;/ul>";
</code></pre>
			</article>

			<article>
				<h4 id="redis_pipelining">Pipelining</h4>
				<p>You can add multiple Redis commands into a command pipeline, and execute them all at once.</p>
				<p>An example:</p>
				<pre class="php"><code>// create the Redis 'mystore' instance
$redis = Redis_Db::forge('mystore');

// pipeline some redis commands, then execute them
$result = $redis->pipeline()
	->sadd('list', 4)
	->sadd('list', 1)
	->sadd('list', 55)
	->execute();</code></pre>
			</article>
		</div>

		<footer>
			<p>
				&copy; FuelPHP Development Team 2010-2013 - <a href="http://fuelphp.com">FuelPHP</a> is released under the MIT license.
			</p>
		</footer>
	</div>
</body>
</html>
